package com.oocl.batchdata.pojo;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Customer implements Comparable<Customer> {

	private int id;
	private String name;
	private String email;
	private boolean sex;
	private Date birthday;
	
	public Customer(int id, String name, String email, boolean sex,
			Date birthday) {
		super();
		this.id = id;
		this.name = name;
		this.email = email;
		this.sex = sex;
		this.birthday = birthday;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public boolean isSex() {
		return sex;
	}

	public void setSex(boolean sex) {
		this.sex = sex;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Customer other = (Customer) obj;
		if (id != other.id)
			return false;
		return true;
	}

	public int compareTo(Customer customer) {
		return id - customer.id;
	}
	
	@Override
	public String toString() {
		return id + "\t" + name + "\t" + sex + "\t" + new SimpleDateFormat("yyyy-MM-dd").format(birthday) + "\t" + email;
	}
	
	public String toXMLString() {
		return "<customer id=\"" + id + "\">\n<name>" + name + "</name>\n<sex>"
				+ sex + "</sex>\n<birthday>"
				+ new SimpleDateFormat("yyyy-MM-dd").format(birthday)
				+ "</birthday>\n<email>" + email + "</email>\n</customer>";
	}
}
